#ifndef __SCNS_TIME_RECORD_H__
#define __SCNS_TIME_RECORD_H__

#include "ScnsConfig.h"

#if defined(SCNS_TIME_RECORD_ENABLE)&&SCNS_TIME_RECORD_ENABLE==1

#include "ScnsYing.h"
#include "ScnsTimer.h"

typedef struct
{
    uint64 tick;
    uint32 line;
}ScnsTimeRecord;

extern void scnsTimeRecord(ScnsTimeRecord*record,int*cnt);
#define ScnsTimeRecordDefine(record,size)           ScnsTimeRecord record[size];int record##Cnt=0
#define scnsTimeRecord(record)                      do{if(record##Cnt<(sizeof(record)/(sizeof(record[0])))){record[record##Cnt]=(ScnsTimeRecord){.tick=scnsTimerGetTick(),.line=__LINE__};++record##Cnt;}}while(0)
#define scnsTimeRecordPrintFormat(record,format)    do  \
    {                                           \
        for(int i=1;i<record##Cnt;++i)          \
        {                                       \
            hxPrintfVFL(__file__,__LINE__,format,\
                record[i-1].line,record[i].line,1e-3*scnsTimerGetUsByTick(record[i].tick-record[i-1].tick),         \
                record[0].line,record[i].line,1e-3*scnsTimerGetUsByTick(record[i].tick-record[0].tick)              \
            );                                  \
        }                                       \
    }while(0)
#define scnsTimeRecordPrint(record)     scnsTimeRecordPrintFormat(record,"from line %4d to %4d %10.4f ms;line %4d to %4d %10.4f ms;\n")
#endif
#endif
